home *** CD-ROM | disk | FTP | other *** search
/ PC User 2007 December / Australian_PC_User_2007-12.iso / software / apps / files / GridinSoft Notepad / gsn3-setup.exe / scripts / tex2ps.js < prev    next >
Encoding:
JavaScript  |  2007-07-26  |  1.9 KB  |  65 lines

  1. // The script converts a .tex file to DVI format using MiKTeX,
  2. // then it takes the DVI file and converts to PostScript using
  3. // GhostScript. All the conversions runs in command line mode.
  4. // After that the script starts GSView to display the document.
  5. // In each stage it catches errors and reports them in pop-up
  6. // message boxes.
  7. //
  8. // Autor: Korolev Sergey (sergey_korolev@inbox.ru)
  9. // Version: 1.0
  10.  
  11. var ICONERROR = 0x10;
  12. var LATEX_CMD = "latex ";
  13. var DVIPS_CMD = "dvips ";
  14. var DVI_EXT = ".dvi";
  15. var PS_EXT = ".ps";
  16.  
  17. if (Application.FileName() == "") {
  18.     Application.Message("Error",
  19.         "Please specify a filename first (save current file).",
  20.         ICONERROR);
  21. } else {
  22.     var Name = "";
  23.     var Ext = "";
  24.     var FullName = Application.FileName();
  25.     var ExtOffset = FullName.lastIndexOf('.');
  26.  
  27.     if (ExtOffset == -1) {
  28.         ExtOffset = FullName.length;
  29.     }
  30.  
  31.     Name = FullName.substring(
  32.         FullName.lastIndexOf('\\') + 1, ExtOffset);
  33.  
  34.     if (ExtOffset + 1 < FullName.length) {
  35.         Ext = FullName.substring(ExtOffset + 1);
  36.     }
  37.  
  38.     Console.SetVisible(true);
  39.  
  40.     if (Shell.FileExist(Name + DVI_EXT)) {
  41.         Shell.DeleteFile(Name + DVI_EXT);
  42.     }
  43.  
  44.     Console.Execute(LATEX_CMD + Name + '.' + Ext);
  45.  
  46.     if (Shell.FileExist(Name + DVI_EXT)) {
  47.         if (Shell.FileExist(Name + PS_EXT)) {
  48.             Shell.DeleteFile(Name + PS_EXT);
  49.         }
  50.  
  51.         Console.Execute(DVIPS_CMD + Name + DVI_EXT);
  52.  
  53.         if (Shell.FileExist(Name + PS_EXT)) {
  54.             Shell.Execute("open", Name + PS_EXT,"","",1);
  55.         } else {
  56.             Application.Message("Error",
  57.                 "Can't convert " + DVI_EXT + " file to "
  58.                 + PS_EXT + " file.", ICONERROR);
  59.         }
  60.     } else {
  61.         Application.Message("Error",
  62.             "There is an error in Latex source file.",
  63.             ICONERROR);
  64.     }
  65. }